package com.ch04.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ch04.vo.AppInfoVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Entity ch04.demos.pojo.AppInfo
 */
@Mapper
public interface AppInfoVOMapper extends BaseMapper<AppInfoVO> {

    @Select("<script>" +
            "select ai.`id`, `softwareName`, `APKName`, `supportROM`, `interfaceLanguage`, `softwareSize`, `updateDate`, `devId`, `appInfo`, `status`, `onSaleDate`, `offSaleDate`, `flatformId`, `downloads`, ai.`createdBy`, ai.`creationDate`, ai.`modifyBy`, ai.`modifyDate`, `categoryLevel1`, `categoryLevel2`, `categoryLevel3`, `logoPicPath`, `logoLocPath`, `versionId` \n" +
            ",dd.valueName flatformName\n" +
            ",(select categoryName from app_category where id =ai.categoryLevel1 ) categoryName1\n" +
            ",(select categoryName from app_category where id =ai.categoryLevel2 ) categoryName2\n" +
            ",(select categoryName from app_category where id =ai.categoryLevel3 ) categoryName3\n" +
            ",dd_status.valueName statusName\n" +
            "from app_info ai\n" +
            "\t,data_dictionary dd\n" +
            "\t,data_dictionary dd_status\n" +
            "where 1=1\n" +
            "  and dd.typeCode='APP_FLATFORM'\t \n" +
            "  and ai.flatformId=dd.valueId\n" +
            "  and dd_status.typeCode='APP_STATUS'\t \n" +
            " and dd_status.valueId =ai.`status`\n" +
            " <if test='appinfo.softwarename!=null'>" +
            "   and ai.softwareName like concat('%',#{appinfo.softwarename},'%')" +
            " </if >" +
            " <if test='appinfo.status!=null'>" +
            "   and ai.status =#{appinfo.status}" +
            " </if >" +
            " <if test='appinfo.flatformid!=null'>" +
            "   and ai.flatformId =#{appinfo.flatformid}" +
            " </if >" +
            " <if test='appinfo.categorylevel1!=null'>" +
            "   and ai.categorylevel1 =#{appinfo.categorylevel1}" +
            " </if >" +
            " <if test='appinfo.categorylevel2!=null'>" +
            "   and ai.categorylevel2 =#{appinfo.categorylevel2}" +
            " </if >" +
            " <if test='appinfo.categorylevel3!=null'>" +
            "   and ai.categorylevel3 =#{appinfo.categorylevel3}" +
            " </if >" +
            " order by ai.creationDate desc,ai.updateDate desc" +

            "</script>")
    public Page<AppInfoVO> getAppinfoList(@Param("page") Page<AppInfoVO> page,@Param("appinfo") AppInfoVO appinfo);
}




